<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="author" content="wangzhichao">
	<title>有个人信息卡客户管理</title>
	<script language="javascript" type="text/javascript" src="../script/common.js"></script>
	<script language="javascript" type="text/javascript">
		//全局变量
		var type="";				//卡片类型
		var orderId="";				//申请单id
		var baseType="";			//基本卡类型
		var userLevel="";			//客户级别
		var isinternal=false;		//是否内部卡
		var location1;				//取当前地址
		var typeName;				//卡片名称
		var detail_editable;		//修改或显示明细
		var restrictedOrg;		//总部目标区域
		var lowerCardNumber		//卡号段初值
		var upperCardNumber		//卡号段末值
		var billId;				//打印id
		var billType;			//打印类型
		function load(){
			Eui.showNavigation();
			location1 = Common.cOrg()	
			orderId = getPara("id");
			setPages(["detview","printview"]);
			detail_editable = parent.detail_editable;
			var eidetButonn = "";
			var backButonn;
			if(orderId){
				detail_editable = false;
				parent.dialog.hideBar();
				backButonn = "<button type='button' onclick='window.close();'>返  回</button>";
			}else{
				orderId = parent.orderId;
				if(detail_editable){
					eidetButonn = "<button type='button' onclick='addRemark()'>修  改</button>";
					backButonn = "<button type='button' onclick='parent.backShow()'>返  回</button>";
				}else{
					backButonn = "<button type='button' onclick='parent.backShow1()'>返  回</button>";
				}
			}
			DWR.call("cardRequestService.getRequestOrder",orderId,function(apply){
				baseType = apply.cardType.baseCardType;
				if(baseType==BaseCardType.PERSONAL){
					userLevel = apply.cardType.userLevel;
				}else if(baseType==BaseCardType.COMPANY){
					isinternal = apply.cardType.internal;
				}
				type = apply.cardType.id;
				typeName = apply.cardType.name
				apply.order.cardType = typeName;
				var status = apply.order.status;
				apply.order.status = Common.getText("cardbill_status",status);
				apply.order.requestType = Common.getText("request_order_type",apply.order.requestType);
				apply.order.createTime = Format.formatToMM(apply.order.createTime);
				Common.showDetail("detview",apply.order);
				if(apply.location.orgLevel == Constants.ORG_LEVEL_HQ){
					$("restrictedOrgTd").innerHTML = "<label>使用区域</label> <span id='restrictedOrg'></span>";
					restrictedOrg = apply.organization.id;
					$("restrictedOrg").innerHTML = apply.organization.name;
				}
				if(status == Constants.CARDBILL_STATUS_CONFIRM){
					backButonn = "<button type='button' onclick='printlnBlankBill()'>打印单据</button>"+backButonn;
					//if(apply.order.hasInfo){
					lowerCardNumber = apply.order.lowerCardNumber;
					upperCardNumber = apply.order.upperCardNumber;
					backButonn = "<button type='button' onclick='downloadFile("+apply.order.hasInfo+"," + apply.order.id+")'>下载文件</button>"+backButonn;
					//}
					$("cardnumbers").innerHTML = "<label>卡片号段</label> <span id='numbers'></span>";
					$("numbers").innerHTML = apply.order.lowerCardNumber+"-"+apply.order.upperCardNumber;
					$("cardSpec").innerHTML = "<label>卡片规格</label> <span id='cardSpecName'></span>";
					$("cardSpecName").innerHTML = apply.cardSpec.name;
				}
				if(apply.order.hasInfo){
					createTable();
				}
				$("eidetButonn").innerHTML = eidetButonn;
				$("backButonn").innerHTML = "<p>" + backButonn + "</p>";
			});
		}
		//查询显示申请数量
		function showAmount(){
			DWR.call("cardRequestService.getRequestOrder",orderId,function(apply){
				$("amount").innerHTML = apply.order.amount;
			});
		}
		//生成查询语句
		function createTable(){
		  	var columns = [];
			var button;
			var discolumns;
			columns[1] = {render:parentfun};
			if(detail_editable){
				if(location1.orgLevel >= Constants.REQUEST_LOWEST_LEVEL){
					button = [
							{value:" 增 加 ",actions:onNew},
							{value:" 删 除 ",actions:onDelete}
							];
				}else{
					if(location1.orgLevel == Constants.ORG_LEVEL_HQ){
						button = [
								{value:" 合并下级单据 ",actions:onMerge},
								{value:" 删 除 ",actions:onDelete}
								];
					}else{
						button = [
									{value:" 合并下级单据 ",actions:onMerge},
									{value:" 增 加 ",actions:onNew},
									{value:" 删 除 ",actions:onDelete}
								];
					}
				}
				columns[0] = {type:"checkbox"};
				if(baseType == BaseCardType.PERSONAL){
					discolumns = [0,1,2,3,6]	
				}else if(baseType == BaseCardType.COMPANY){
					columns[4] = {render:companyfun};
					discolumns = [0,1,2,4,5,6]
				}
			}else{
				if(baseType == BaseCardType.PERSONAL){
					discolumns = [1,2,3,6]	
				}else if(baseType == BaseCardType.COMPANY){
					columns[4] = {render:companyfun};
					discolumns = [1,2,4,5,6]
				}
			}
			qt = new QueryTable("card_request_user",null,"datalist",columns,{
				buttons:button,
				showData:true,
				displayColumns:discolumns,
				title:typeName+"客户申请列表"
			});
			qt.paramFunc = function(){
				var type1 = CardUserType.NAME;
				if(baseType == BaseCardType.PERSONAL){
					type1 = CardUserType.NAME;
				}else if(baseType == BaseCardType.COMPANY){
					type1 = CardUserType.DRIVER;
				}
				return {cardRequestOrder:orderId,type:type1}
			}
		}
		//客户名称的超链接
		function parentfun(v,r){
			return "<a href=# onclick=showDetailparent("+r[0]+","+r[8]+")>"+v+"</a>"
		}
		//点击弹出客户明细信息
		function showDetailparent(userId,cuId){
			var ckSize = 655;
			if(!cuId){
				ckSize = 415;
			}
			var v = openDialogFrame("/store/sel_customer_and_company_detail.html?userId="+userId+"&cuId="+cuId+"&cardUserType="+CardUserType.NAME,'司机明细信息',ckSize,750);
		}
		function companyfun(v,r){
			return "<a href=# onclick=showDetailUnit("+r[7]+","+r[9]+")>"+v+"</a>"
		}
		function showDetailUnit(userId,cuId){
			var v = openDialogFrame("/store/sel_customer_and_company_detail.html?userId="+userId+"&cuId="+cuId+"&cardUserType="+CardUserType.COMPANY,'单位明细信息',730,750);
		}
		//新增申请客户
		function onNew(){
			var v = openDialogFrame("/store/add_customer.html?idd="+orderId+"&titlename="+typeName+"&cardType="+type+"&baseType="+baseType,'选择客户',480,640)
			if (v){
				showAmount()
				qt.showTable()
			}
		}
		function onMerge(){
			var v = openDialogFrame("/store/sel_req_order.html?newId="+orderId+"&ct="+type+"&isPersent="+true+"&restrictedOrg="+restrictedOrg,"选择申请单",500,710);
			if (v){
				showAmount()
				qt.showTable();
			}
		}
		//删除申请客户
		function onDelete(){		
		    var ids1 = qt.getBoxValue();
		    if(ids1==null||ids1==""){
				showInformation("请选择您要删除的数据");return;
			}
			if(!(showQuestion("您确认删除吗?"))){
				return;
			}
			ids1 = ids1.split(",");
            DWR.call("cardRequestService.cancelCustomer",orderId,ids1,function(){
				showInformation("删除成功!");
				showAmount()
				qt.showTable()
			});
		}
		//修改基本信息
		function addRemark(){
			var v = openDialogFrame("/store/request_basic_info.html?taskId="+ orderId + "&requestComment="+ $("requestComment").innerHTML +"&completeDate="+$("completeDate").innerHTML + "&tagData="+true ,"修改备注",200,350);
			if(v){
				var cliect = v;
				if(cliect.requestComment==null||cliect.requestComment==""){
					cliect.requestComment = "";
				}
				if(cliect.completeDate==null||cliect.completeDate==""){
					cliect.completeDate = "";
				}
				$("requestComment").innerHTML = cliect.requestComment;
				$("completeDate").innerHTML = cliect.completeDate;
			}
		}
		//查看操作明细
		function selOperatelog(){
			var v = openDialogFrame("/store/operation_log.html?orderId="+orderId+"&logType="+3,'操作明细',455,700)
		}
		function printlnBlankBill(){
			billId = orderId;
			billType = 999;
			requestframe.document.location.href = "print_blank_bill.html";
			switchPage("printview");
			//var v = openDialogFrame("/store/print_blank_bill.html?billType="+billType+"&billId="+orderId,"打印单据",450,700);
		}
		//返回方法
		function closePrintDialog(){
			switchPage("detview");
		}
	    //下载文件
		function downloadFile(hasinfo, orderId){
			var downLoadString = "";
			if(hasinfo){
				downLoadString = "card_file_with_user";
			}else{
				downLoadString = "card_file_without_user";
				if(baseType == BaseCardType.PSAM){
					downLoadString = "card_file_psam";
				}
			}
			//var filename = 'cardfile_' + typeName + "_" + orderId + "_" + new Date().format("yyMMddhhmmss")+'.imp';
			var filename = 'cardfile_' + orderId + "_" + new Date().format("yyMMddhhmmss")+'.imp';
			var params = {filename:filename,lowerCardNumber:lowerCardNumber,upperCardNumber:upperCardNumber}
			var path = appRoot + 'd/list/'+ downLoadString +'.csv'
			var query = "";
			var prop
			for (prop in params) {
				if (typeof params[prop] != "function"&&params[prop]) {
					query += prop + "=" + encodeURIComponent(params[prop]) + "&";
				}
			}
			if (query!="")
				path += '?'+query
			document.location.href=path
	    }
	
	</script>
</head>
<body onload="load()">
	<div class="detview" id="detview">
		<form id="makecardform" name="makecardform">
		    <input type="hidden" id="id" name="id">
			<div class=form>
			<div class="formTitle">
				<table width="100%" cellSpacing=0 cellPadding=0 border=0>
					<tr><td>单据明细</td><td align="right"><span id="eidetButonn"></span><button type="button" onclick="selOperatelog()">查看操作明细</button></td><tr>
				</table>
			</div>
			<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="viewTable">
				<tr>
					<td><label>单据编号</label> <span id="id"></span></td>
					<td><label>卡片类型</label> <span id="cardType"></span></td>
				</tr>
				<tr>
					<td><label>需求数量</label> <span id="amount"></span></td>
					<td><label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label> <span id="status"></span></td>
				</tr>
				<tr>
					<td><label>创建时间</label> <span id="createTime"></span></td>
					<td><label>完成日期</label> <span id="completeDate"></span></td>
				</tr>
				<tr>
					<td><label>备&nbsp;&nbsp;&nbsp;&nbsp;注</label> <span id="requestComment"></span></td>
					<td id="restrictedOrgTd"></td>
				</tr>
				<tr>
					<td id="cardnumbers"></td>
					<td id="cardSpec"></td>
				</tr>
			</table>
			</div>
		</form>
		<div id="datalist"></div>
		<span id="backButonn"></span>
	</div>
			
	<div class="printview" id="printview" style='display:none;'>
		<iframe id="requestframe" name="requestframe" style="width:100%;height:90%;overflow:auto;" frameborder=0 src=""></iframe>
	</div>
</body>
</html>
